home *** CD-ROM | disk | FTP | other *** search
- Path: news.mcs.net!usenet
- From: mikey@mcs.com (Mike Young)
- Newsgroups: comp.lang.ada,comp.lang.c++
- Subject: Re: Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user)
- Date: 31 Mar 1996 10:27:49 GMT
- Organization: Fen Software, Inc.
- Message-ID: <4jlmn5$h1k@Nntp1.mcs.net>
- References: <wnewmanDoxrCp.DKv@netcom.com> <Dp1oAw.7Cz@world.std.com> <EACHUS.96Mar29191146@spectre.mitre.org>
- NNTP-Posting-Host: mikey.pr.mcs.net
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.6
-
- In article <EACHUS.96Mar29191146@spectre.mitre.org>, eachus@spectre.mitre.org>
- says...
- >some tools over the code. The choice was between Ada and a shell
- >script...I chose Ada:
- >
- >generic
- > with procedure To_Do(File: in String);
- >procedure Iterate_Files(Pattern: in String := "*";
- > Directory: in String := "");
- >-- This generic iterates over all files in a directory matching Pattern and
- >-- calls To_Do once for each such directory entry. If a file has several
- >-- links in the directory To_Do will be called once for each.
-
- =========
- I don't know about that, Robert. The equivalent shell script would be:
-
- #---- iterateFiles
- fileop=$1;shift
- for file in $*; do $fileop $file; done
-
- You would call it thusly:
-
- iterateFiles 'head -n 3' *.ada >header.comments
-
- or, directly, without a script:
- for file in *.ada; do head -n 3 $file; done >header.comments
-
- or, in Windows NT or 95:
- for %i in (*.ada) do gnatchop -s -w %i
-
- You are not restricted to procedures in that same program, all system utilities
- are directly available, you don't need to rebuild to add new features, and you
- need not have bothered with your 50 lines of code. All are big wins, IMO. You
- can always write small, easy to maintain, helper programs if available
- utilities don't do what you need.
-
- >
- >
- > Two observations. First, the generic procedure approach is
- >certainly right for this case. Second, the VADS run-time provided a
- >call for freeing A_Strings, but not for find_files.find_file_rec, so I
-
- ===========
- Hmmm.
-
- Mike.
-
-